package com.webchat.pay.repository.dao;

import com.webchat.pay.repository.entity.PaymentOrderDetailEntity;
import com.webchat.pay.repository.entity.PaymentOrderEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface IPaymentOrderDetailDAO extends
        JpaSpecificationExecutor<PaymentOrderDetailEntity>,
        JpaRepository<PaymentOrderDetailEntity, Long> {

    /**
     * 查询账户余额
     *
     * @param account
     * @return
     */
    @Query(value = "select sum(pod.amount) from web_chat_payment_order_detail pod " +
            "where pod.source_account = :account and pod.status = 1", nativeQuery = true)
    BigDecimal getAccountBalance(String account);

    List<PaymentOrderDetailEntity> findAllByOrderId(String orderId);
}
